<template>
  <div class="app-container">
    <!-- 个人信息 -->
    <el-form ref="refs" label-width="100px" :model="userDate" :rules="rules">
      <!-- 部门 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="部门" prop="departmentName">
            <el-input v-model="userDate.departmentName" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 入职时间 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="入职时间" prop="timeOfEntry">
            <el-date-picker v-model="userDate.timeOfEntry" type="date" class="inputW" value-format="yyyy-MM-dd" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 员工照片 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="员工头像">
            <!-- 放置上传图片 -->
            <el-image :src="require('@/assets/common/head.jpg')" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 保存个人信息 -->
      <el-row class="inline-info" type="flex" justify="center">
        <el-col :span="12">
          <el-button type="primary" @click="saveUpdata">保存更新</el-button>
          <el-button @click="$router.back()">返回</el-button>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { saveUserDetailById } from '@/api/employees.js'
export default {
  props: {
    userDate: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      rules: {
        departmentName: [{ required: true, min: 2, max: 10, message: '部门名称必填', trigger: 'change' }],
        timeOfEntry: [{ required: true, message: '请选择入职时间', trigger: ['blur', 'change'] }]
      }
    }
  },
  methods: {
    async saveUpdata() {
      try {
        await this.$refs.refs.validate()
        await saveUserDetailById(this.userDate)
        this.$message.success('修改成功')
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style></style>
